package a02;

import java.awt.Color;
import java.util.List;

import util.Pair;

public class OthelloBoard<M> extends RegularBoard<M> {
    private static final long serialVersionUID = 1L;
    private List<Pair<Byte, Byte>> lastTaken = null;

    public OthelloBoard(RegularGame<M> game) {
	super(game);
    }

    @Override
    public void paintLastMove(byte c, byte r) {
	if (getLastMove() != null && !isTaken(c, r) && c == getLastMove().fst
		&& r == getLastMove().snd) {
//	    getTheGraphics().setColor(Color.GREEN);
	    getTheGraphics().setColor(selectColor(getGame().currentPlayer()));
	    getTheGraphics().fillOval(
		    (c * this.getUNIT()) + ((this.getUNIT() / 2) - 8),
		    (r * this.getUNIT()) + ((this.getUNIT() / 2) - 8),
		    (this.getUNIT()) - ((this.getUNIT() / 2) + 17),
		    (this.getUNIT()) - ((this.getUNIT() / 2) + 17));
	    getTheGraphics().setColor(Color.GREEN);	    
	    getTheGraphics().fillOval(
		    (c * this.getUNIT()) + ((this.getUNIT() / 2) - 4),
		    (r * this.getUNIT()) + ((this.getUNIT() / 2) - 4),
		    (this.getUNIT()) - ((this.getUNIT() / 2) + 25),
		    (this.getUNIT()) - ((this.getUNIT() / 2) + 25));
	} else if (getLastMove() != null && isTaken(c, r)) {

	    getTheGraphics().setColor(selectColor(getGame().currentPlayer()));
	    // getTheGraphics().setColor(Color.YELLOW);

	    getTheGraphics().fillOval(
		    (c * this.getUNIT()) + ((this.getUNIT() / 2) - 4),
		    (r * this.getUNIT()) + ((this.getUNIT() / 2) - 4),
		    (this.getUNIT()) - ((this.getUNIT() / 2) + 25),
		    (this.getUNIT()) - ((this.getUNIT() / 2) + 25));
	}
    }

    private boolean isTaken(byte c, byte r) {
	return getLastTaken() == null ? false : getLastTaken().contains(
		new Pair<Byte, Byte>(c, r));
    }

    @Override
    public List<Pair<Byte, Byte>> getLastTaken() {
	return lastTaken;
    }

    @Override
    public void setLastTaken(List<Pair<Byte, Byte>> lastTaken) {
	this.lastTaken = lastTaken;
    }

}
